cap cd "D:\Dropbox\RCT on corruption & productivity\Replication"
cap cd "C:\Users\ejm5\Dropbox\RCT on corruption & productivity\Replication"
use "DUKE_RESTAURANT_ENDLINE_MERGED_WORKING.dta", clear
set scheme plottig


/***********************************************************************************************/
/*Balance - Appendix D1*/
generate city2=city*100
lab var city2 "In National City (%)"
generate south2=south*100
lab var south2 "In South Vietnam (%)"
generate female2=female*100
lab var female2 "Female CEO (%)"
generate coffee2=coffee*100
lab var coffee2 "Coffee Shop %)"
generate single_dish2=single_dish*100
lab var single_dish2 "Single Dish Restaurant %)"
generate multi_dish2=multi_dish*100
lab var multi_dish2 "Multi-Dish Restaurant"
generate hotel2=hotel*100
lab var hotel2 "Hotel Restaurant"
generate profit_margin2=profit_margin*100
label var profit_margin2 "Profit Margin *100"


ciplot city2, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(In National City) xlab(0(10)100, labsize(small)) msize(medium) fxsize(100) ylab(, labsize(medmsmall))
graph save "graph\balance_city.gph", replace

ciplot south2, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(In South VN) xlab(0(10)100, labsize(small)) msize(medium) ylabel(, nolabels) fxsize(55)
graph save "graph\balance_south.gph", replace

ciplot exp_employees, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(Employees) xlab(0(1)15, labsize(small)) msize(medium) ylabel(, nolabels) fxsize(55)
graph save "graph\balance_employees.gph", replace

ciplot female2, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(Female CEO)  xlab(0(10)100, labsize(small)) msize(medium) ylabel(, nolabels) fxsize(55)
graph save "graph\balance_female.gph", replace

ciplot coffee2, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(Coffee Shop)  xlab(0(10)100, labsize(small)) msize(medium) fxsize(100) ylab(, labsize(medmsmall))
graph save "graph\balance_coffee.gph", replace

ciplot single_dish2, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(Single Dish Restaurant)  xlab(0(10)100, labsize(small)) msize(medium)  ylabel(, nolabels) fxsize(55)
graph save "graph\balance_single_dish.gph", replace

ciplot multi_dish2, by(treatment) horizontal ytitle("") note("") xtitle(%, size(medium) margin(medsmall)) title(Multi-Dish Restaurant)  xlab(0(10)100, labsize(small)) msize(medium) ylabel(, nolabels) fxsize(55)
graph save "graph\balance_multi_dish.gph", replace

graph combine "graph\balance_coffee.gph" "graph\balance_single_dish.gph"  "graph\balance_employees.gph" "graph\balance_city.gph" "graph\balance_south.gph" "graph\balance_female.gph" ,  ycommon note("Diamond=Mean; Range Bars=95% Confidence Intervals", size(vsmall) position(7)) imargin(tiny)
graph save "graph\Appendix_FigureD1.gph", replace
graph export "graph\Appendix_FigureD1.png", replace
/***********************************************************************************************/
/*Descriptive Statistics - Table 6*/
estpost summarize sec1_q15 bribe_dich sec1_q2 exp_total profit profit_margin sec1_q22 pictures_no  knowledge inspections fines city south female coffee single_dish multi_dish hotel
esttab using "tables\Table6", cells("count mean sd min max") replace
/***********************************************************************************************/
/*Figure 3 Bribery*/
graph bar (count) stt, over(treatment) bar(1, fcolor(blue)) title("Endline Respondents") ylab(0(2)30, labsize(small)) ytitle("Respondents (#)", size(medsmall) margin(medsmall)) blabel(bar, size(small) color(black) position(Inside) format(%4.0f)) 
graph save "graph\respondents.gph", replace

graph bar bribe_dich2, over(treatment) bar(1, fcolor(blue)) title("Paid Bribe Last Month") ylab(0(10)80, labsize(small)) ytitle("Share of Firms (%)", size(medsmall) margin(medsmall)) blabel(bar, size(small) color(black) position(Inside) format(%4.1f)) 
graph save "graph\bribe_any.gph", replace

graph bar sec1_q15, over(treatment) bar(1, fcolor(navy)) title("Amount Paid Last Month") ylab(0(20)300, labsize(small)) ytitle("USD", size(medsmall) margin(medsmall)) blabel(bar, size(small) color(black) position(Inside) format(%4.1f))
graph save "graph\bribe_amount.gph", replace

graph combine "graph\bribe_any.gph" "graph\bribe_amount.gph", xcommon rows(2) imargin(medsmall)
graph save "graph\Figure3_Bribes.gph", replace
graph export "graph\Figure3_Bribes.png", replace
/***********************************************************************************************/
/*Table 7: Main Effects on Bribery*/
bootstrap, rep(1000) seed (2024): areg  bribe_dich MBA IC , robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse)  replace
bootstrap, rep(1000) seed (2024): areg  bribe_dich MBA IC city south, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  bribe_dich MBA IC city south female, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  bribe_dich MBA IC city south female coffee, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  sec1_q15 MBA IC, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  sec1_q15  MBA IC city south, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  sec1_q15  MBA IC city south female, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  sec1_q15  MBA IC city south female coffee, robust absorb(wave2)  
outreg2 using "tables\Table7_Boot", tdec(3) bdec(3) e(rmse)  excel
/***********************************************************************************************/
/*Appendix Table F2: Productivity*/
replace exp_total=exp_total/1000
gen revenue  =sec1_q2/1000
replace profit=profit/1000

bootstrap, rep(1000) seed (2024): areg exp_total MBA IC city south female coffee , robust absorb(wave2) 
outreg2 using "tables\Appendix_TableF2_Boot", tdec(3) bdec(3) e(rmse)  excel replace
bootstrap, rep(1000) seed (2024): areg  revenue  MBA IC city south female coffee, robust absorb(wave2) 
outreg2 using "tables\Appendix_TableF2_Boot", tdec(3) bdec(3) e(rmse)   excel
bootstrap, rep(1000) seed (2024): areg  profit  MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF2_Boot", tdec(3) bdec(3) e(rmse)  excel
bootstrap, rep(1000) seed (2024): areg  profit_margin  MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF2_Boot", tdec(3) bdec(3) e(rmse)   excel
bootstrap, rep(1000) seed (2024): areg  sec1_q22  MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF2_Boot", tdec(3) bdec(3) e(rmse)   excel
/***********************************************************************************************/
/*Appendix Table F1: Regulation*/
bootstrap, rep(1000) seed (2024): areg pictures_no MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF1_Boot", tdec(3) bdec(3) e(rmse)   excel replace
bootstrap, rep(1000) seed (2024): areg  knowledge  MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF1_Boot", tdec(3) bdec(3) e(rmse)   excel 
bootstrap, rep(1000) seed (2024): areg inspections MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF1_Boot", tdec(3) bdec(3) e(rmse)   excel
bootstrap, rep(1000) seed (2024): areg  fines  MBA IC city south female coffee, robust absorb(wave2)
outreg2 using "tables\Appendix_TableF1_Boot", tdec(3) bdec(3) e(rmse)  excel

/****************************************************************************************************/
/*Appendix Table E2 - Treatment Effect on Treated*/
bootstrap, rep(1000) seed (2024): areg  bribe_dich  MBA IC if lessons>0, robust absorb(wave2)  
outreg2 using "tables\Appendix_TableE2", tdec(3) bdec(3) e(rmse) replace
bootstrap, rep(1000) seed (2024): areg  sec1_q15  MBA IC  if lessons>0, robust absorb(wave2)  
outreg2 using "tables\Appendix_TableE2", tdec(3) bdec(3) e(rmse)  
bootstrap, rep(1000) seed (2024): areg  bribe_dich  MBA IC city south female coffee if lessons>0, robust absorb(wave2)  
outreg2 using "tables\Appendix_TableE2", tdec(3) bdec(3) e(rmse) 
bootstrap, rep(1000) seed (2024): areg  sec1_q15  MBA IC city south female coffee if lessons>0, robust absorb(wave2)  
outreg2 using "tables\Appendix_TableE2", tdec(3) bdec(3) e(rmse)  excel


/***********************************************************************************************/
/*Unmatched Count Technique*/

use "DUKE_RESTAURANT_ENDLINE_MERGED_WORKING.dta", clear
/*Individual Treatments*/
reg activities2 MBA IC if UCT2==0
predict count2
generat bribe2=activities2-count2
bootstrap, rep(1000) seed (2024): reg bribe2 MBA IC if UCT2==1
outreg2 using "tables\Appendix_TableE1", tdec(3) bdec(3) e(rmse) replace  
drop bribe2 count2

reg activities2 MBA IC  city south female coffee if UCT2==0
predict count2
generat bribe2=activities2-count2
bootstrap, rep(1000) seed (2024):  reg bribe2 MBA IC  city south female coffee if UCT2==1
outreg2 using "tables\Appendix_TableE1", tdec(3) bdec(3) e(rmse) 
drop bribe2 count2

reg inspection_expenditures MBA IC if UCT2==0
predict amount2
generat bribe4=inspection_expenditures-amount2
bootstrap, rep(1000) seed (2024): reg bribe4 MBA IC if UCT2==1
outreg2 using "tables\Appendix_TableE1", tdec(3) bdec(3) e(rmse)  
drop bribe4 amount2

reg inspection_expenditures MBA IC city south female coffee if UCT2==0
predict amount2
generat bribe4=inspection_expenditures-amount2
bootstrap, rep(1000) seed (2024): reg bribe4 MBA IC city south female coffee if UCT2==1
outreg2 using "tables\Appendix_TableE1", tdec(3) bdec(3) e(rmse)  excel
drop bribe4 amount2
/************************************************************************************************/
/*Figure 4: Calculation of Share of Firms Bribing During Inspections*/

use "DUKE_RESTAURANT_ENDLINE_MERGED_WORKING.dta", clear
mean activities2, over(treatment UCT2)
mat list e(b)
mat mean =e(b)'
mat list e(V)
mat var =e(V)'

collapse activities2, by(treatment UCT2)
svmat mean
svmat var
generate variance=var1+var2+var3+var4+var5+var6
drop mean1 var1 var2 var3 var4 var5 var6

scalar define t_crit=invttail(45, .05)
display t_crit
generate high=activities2+(sqrt(variance)*t_crit)
generate low=activities2-(sqrt(variance)*t_crit)
format  activities2 %9.2f
generate treatment_plus=.5

xtset treatment UCT2 
generate bribe=d.activities2
format bribe %9.4f
generate bribe2=(bribe)*100
format bribe2 %9.2f
/*replace bribe2=round(bribe2, 1)*/
tostring bribe2, replace force
replace bribe2 = "53" in 2
replace bribe2 = "65" in 4
replace bribe2 = "-33" in 6

generate avg_activity=(activities2+l.activities2)/2
generate label1="% Bribe"
egen label2 = concat(bribe2 label1)

#delimit;
xtset treatment UCT2 ;
twoway (rcap low high UCT2 if treatment==1, lwidth(medthick) lcolor(navy)) 
(scatter activities2 UCT2 if treatment==1, msize(vsmall) mlab(activities2) mlabcolor(black) mlabposition(3) msymbol(diamond) mcolor(maroon))
(rspike l.activities2 activities2 treatment_plus if treatment==1, lwidth(medthin) lcolor(black) lpattern(shortdash))
(scatter avg_activity treatment_plus if treatment==1, msymbol(i) msize(tiny) mcolor(black) mlab(label2) mlabcolor(maroon) mlabsize(small) mlabposition(3)),
xlab(0(1)1, valuelabels) xtitle("") ytitle("Mean number of activities during inspection", size(medsmall) margin(medsmall)) ylab(0(.2)3, labsize(small)) legend(off) title("Internal Controls");
graph save "graph\UCT_IC.gph", replace;


#delimit;
xtset treatment UCT2 ;
twoway (rcap low high UCT2 if treatment==2, lwidth(medthick) lcolor(navy)) 
(scatter activities2 UCT2 if treatment==2, msize(vsmall) mlab(activities2) mlabcolor(black) mlabposition(3) msymbol(diamond) mcolor(maroon))
(rspike l.activities2 activities2 treatment_plus if treatment==2, lwidth(medthin) lcolor(black) lpattern(shortdash))
(scatter avg_activity treatment_plus if treatment==2, msymbol(i) msize(tiny) mcolor(black) mlab(label2) mlabcolor(maroon) mlabsize(small) mlabposition(3)),
xlab(0(1)1, valuelabels) xtitle("") ytitle("Mean number of activities during inspection", size(medsmall) margin(medsmall)) ylab(0(.2)3, labsize(small)) legend(off) title("Marketing (Placebo)");
graph save "graph\UCT_MARK.gph", replace;


#delimit;
xtset treatment UCT2 ;
twoway (rcap low high UCT2 if treatment==3, lwidth(medthick) lcolor(navy)) 
(scatter activities2 UCT2 if treatment==3, msize(vsmall) mlab(activities2) mlabcolor(black) mlabposition(3) msymbol(diamond) mcolor(maroon))
(rspike l.activities2 activities2 treatment_plus if treatment==3, lwidth(medthin) lcolor(black) lpattern(shortdash))
(scatter avg_activity treatment_plus if treatment==3, msymbol(i) msize(tiny) mcolor(black) mlab(label2) mlabcolor(maroon) mlabsize(small) mlabposition(3)),
xlab(0(1)1, valuelabels) xtitle("") ytitle("Mean number of activities during inspection", size(medsmall) margin(medsmall)) ylab(0(.2)3, labsize(small)) legend(off) title("Management");
graph save "graph\UCT_MBA.gph", replace;

#delimit;
graph combine "graph\UCT_IC.gph" "graph\UCT_MARK.gph"  "graph\UCT_MBA.gph", cols(3) xcommon ycommon imargin(medlarge) note("Diamond=Mean; Range Bars=95% Confidence Intervals", size(vsmall) position(7)); 
graph save "graph\Figure4_UCT.gph", replace;
graph export "graph\Figure4_UCT.png", replace;




